package com.yanqu.road.server.cmd.tradewar.team;

import com.yanqu.road.entity.tradewar.UserCrossTradeWarTeam;
import com.yanqu.road.entity.tradewar.UserTradeWarTeam;
import com.yanqu.road.pb.tradewar.team.TradeWarTeamProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.TradeWarTeamModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_TRADE_WAR_TEAM_SET_BUY_BUFF, desc = "商战队伍设置鼓舞")
public class TradeWarSetTeamBuyBuffCmd extends AbstractCommand {

	private int index;
	private int type;
	private int teamType = 0;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		TradeWarTeamProto.TradeWarTeamSetBuyBuffReqMsg reqMsg = TradeWarTeamProto.TradeWarTeamSetBuyBuffReqMsg.parseFrom(packet.getBytes());
		index = reqMsg.getTeamIndex();
		type = reqMsg.getType();
		if (reqMsg.hasTeamType()){
			teamType = reqMsg.getTeamType();
		}
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(TradeWarTeamModule.class).setTradeWarTeamBuyBuff(index, type, teamType);
	}

	@Override
	public void sendData(GamePlayer player) {
		TradeWarTeamProto.TradeWarTeamSetBuyBuffRespMsg.Builder respMsg = TradeWarTeamProto.TradeWarTeamSetBuyBuffRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret) {
			respMsg.setTeamType(teamType);
			if (teamType==0){
				UserTradeWarTeam userTradeWarTeam = player.getModule(TradeWarTeamModule.class).getUserTradeWarTeam();
				respMsg.setTeamBuyBuffData(userTradeWarTeam.getBuyBuffTimesListString());
			}else{
				UserCrossTradeWarTeam userCrossTradeWarTeam = player.getModule(TradeWarTeamModule.class).getUserCrossTradeWarTeam();
				respMsg.setTeamBuyBuffData(userCrossTradeWarTeam.getBuyBuffTimesListString());
			}

		}
		player.sendPacket(Protocol.U_TRADE_WAR_TEAM_SET_BUY_BUFF, respMsg);
	}

}
